using namespace std;
struct Time{
int hour, min;
Time(){}
Time(string t){
hour=stoi(t.substr(0, 2));
min=stoi(t.substr(3, 2));
}
string now(void){
char h[3], m[3];
snprintf(h, 3, "%02d", hour); snprintf(m, 3, "%02d", min);
string t=string(h)+":"+string(m);
return t;
}
Time after(int t){
min+=t;
if(min>=60){
hour+=min/60;
min%=60;
} else if(min<0){
hour-=min/60+1;
while(min<0) min=60+min;
}
Time tmp(this->now());
return tmp;
}
bool is_before(const Time* other){
if(this->hour<other->hour) {
return true;
} else if(this->hour==other->hour){
if(this->min<other->min) return true;
} else {
return false;
}
return false;
}
};
string solution(int n, int t, int m, vector<string> Timetable){
sort(Timetable.begin(), Timetable.end());
string answer="";
vector<Time> arrive_bus;
vector<Time> line;
Time bus("09:00");
for(int i=0; i<n; ++i){
arrive_bus.push_back(bus);
bus.after(t);
}
for(int i=0; i<Timetable.size(); ++i){
line.push_back(Time(Timetable[i]));
}
int index=0;
for(int i=0; i<arrive_bus.size(); ++i){
int maxppl=m;
for(int j=index; j<line.size(); ++j){
if(!arrive_bus[i].is_before(&line[j]) && maxppl){
index++;
maxppl--;
if(i==arrive_bus.size()-1 && !maxppl) {
answer=line[j].after(-1).now();
return answer;
}
} else break;
}
}
answer=arrive_bus[arrive_bus.size()-1].now();
return answer;
}
int main(void){
int n1=1, t1=1, m1=5, n2=2, t2=10, m2=2, n3=2, t3=1, m3=2;
int n4=1, t4=1, m4=5, n5=1, t5=1, m5=1, n6=10, t6=60, m6=45;
vector<string> Timetable1={"08:00", "08:01", "08:02", "08:03"};
vector<string> Timetable2={"09:10", "09:09", "08:00"};
vector<string> Timetable3={"09:00", "09:00", "09:00", "09:00"};
vector<string> Timetable4={"00:01", "00:01", "00:01", "00:01", "00:01"};
vector<string> Timetable5={"23:59"};
vector<string> Timetable6={"23:59","23:59", "23:59", "23:59", "23:59", "23:59", "23:59", "23:59", "23:59", "23:59", "23:59", "23:59", "23:59", "23:59", "23:59", "23:59"};
string result1=solution(n1, t1, m1, Timetable1);
string result2=solution(n2, t2, m2, Timetable2);
string result3=solution(n3, t3, m3, Timetable3);
string result4=solution(n4, t4, m4, Timetable4);
string result5=solution(n5, t5, m5, Timetable5);
string result6=solution(n6, t6, m6, Timetable6);
cout<<"result1: "<<result1<<endl;
cout<<"result2: "<<result2<<endl;
cout<<"result3: "<<result3<<endl;
cout<<"result4: "<<result4<<endl;
cout<<"result5: "<<result5<<endl;
cout<<"result6: "<<result6<<endl;
return 0;
}